package com.uphone.edwards.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public abstract class MybaseAdapter<T> extends BaseAdapter {
	protected List<T> list;
	protected LayoutInflater inflater;

	public MybaseAdapter(Context context) {
		list = new ArrayList<T>();
		inflater = LayoutInflater.from(context);
	}

	public void setListTop(T t) {
		list.add(0, t);
		notifyDataSetChanged();
	}

	public void setListTop(List<T> date) {
		list.addAll(0, date);
		notifyDataSetChanged();
	}

	public void setListBottom(T t) {
		list.add(t);
		notifyDataSetChanged();
	}

	public void setListBottom(List<T> date) {
		list.addAll(date);
		notifyDataSetChanged();
	}

	public void setData(List<T> date) {
		if(date!=null){
		list.clear();
		list.addAll(date);
		notifyDataSetChanged();
	}
	}
	
	public void remove(T t){
		list.remove(t);
	}

	public List<T> getData() {
		// TODO Auto-generated method stub
		return this.list;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}
	@Override
	public T getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View converView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return setView(position, converView, parent);
	}
	public abstract View setView(int position, View converView, ViewGroup parent);

}
